package com.gsx.mapper;

import com.gsx.entity.Blog_Type_User;
import com.gsx.entity.Type;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TypeMapper{
    @Insert("insert into type(type_id,type_name) values(#{type_id},#{type_name})")
    public int saveType(Type type);

    @Select("select * from type where type_id=#{type_id}")
    public Type getType(Long id);

    @Select("select * from type")
    public List<Type> getListType();

    @Update("update type set type_name=#{type_name} where type_id=#{type_id}")
    public int updateType(Type type);

    @Delete("delete from type where type_id=#{type_id}")
    public int deleteType(Long id);

    @Select("select * from type where type_name=#{type_name}")
    public Type getTypeByName(String name);


    @Select(" select * from type ")
    public List<Type> getAll();


    @Select("SELECT b.blog_id,b.title,b.content,b.description,b.firstPicture,b.views,b.appreciation,b.shareStatement,b.commentable,b.published,b.recommend,b.updateTime,b.flag,t.type_name,t.type_id,u.user_id,u.nickname,u.avatar  " +
            "FROM blog AS b INNER JOIN USER AS u ON b.user_id=u.user_id " +
            "INNER JOIN TYPE AS t ON b.type_id=t.type_id where t.type_id=#{type_id}")
    public List<Blog_Type_User> getBlog_Type_User(Long type_id);
}
